package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.Ship;
import asteroids.model.programs.parsing.types.DoubleLiteral;
import asteroids.model.programs.parsing.types.Type;

/**
 * A class of addition expressions.
 * An addition expression involves an add operation between a left-hand operand and a right-hand operand.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public class AddExpr extends ArithmeticExpr {

	public AddExpr(Expression e1, Expression e2,int column, int line) {
		super(e1, e2,column, line);
	}

	@Override
	public Type eval(Ship ship, Map<String, Type> globals) {
		Type t1=super.getLeftOperand().eval(ship, null);
		Type t2=super.getRightOperand().eval(ship, null);

		if(t1 instanceof DoubleLiteral && t2 instanceof DoubleLiteral) {
			return new DoubleLiteral(((DoubleLiteral) t1).getValue() + ((DoubleLiteral) t2).getValue());
		}
		return new DoubleLiteral();
	}
}
